```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java并发工具详解 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .code-block {
            background: #2d3748;
            color: #f8f8f2;
            border-radius: 0.5rem;
            position: relative;
        }
        .code-header {
            background: rgba(0,0,0,0.2);
            padding: 0.5rem 1rem;
            border-top-left-radius: 0.5rem;
            border-top-right-radius: 0.5rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .code-copy {
            cursor: pointer;
            transition: all 0.3s;
        }
        .code-copy:hover {
            color: #63b3ed;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .tooltip:hover .tooltip-text {
            visibility: visible;
            opacity: 1;
        }
        .tooltip-text {
            visibility: hidden;
            opacity: 0;
            transition: opacity 0.3s;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-4xl mx-auto text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">Java并发编程工具详解</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">探索多线程协作的强大工具 - 让并发编程更优雅</p>
            <div class="flex justify-center space-x-4">
                <a href="#countdownlatch" class="bg-white text-indigo-600 hover:bg-gray-100 px-6 py-3 rounded-full font-medium transition duration-300">CountDownLatch</a>
                <a href="#cyclicbarrier" class="bg-indigo-600 text-white hover:bg-indigo-700 px-6 py-3 rounded-full font-medium transition duration-300">CyclicBarrier</a>
                <a href="#semaphore" class="bg-white text-indigo-600 hover:bg-gray-100 px-6 py-3 rounded-full font-medium transition duration-300">Semaphore</a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- Visualization Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">并发工具对比</h2>
            <div class="bg-white rounded-xl shadow-lg p-6">
                <div class="mermaid">
                    graph TD
                    A[Java并发工具] --> B[CountDownLatch]
                    A --> C[CyclicBarrier]
                    A --> D[Semaphore]
                    B -->|一次性使用| E[等待多个任务完成]
                    C -->|可重复使用| F[线程同步到某个点]
                    D -->|资源控制| G[限制同时访问的线程数]
                    style A fill:#4F46E5,color:#fff,stroke:#4F46E5
                    style B fill:#7C3AED,color:#fff,stroke:#7C3AED
                    style C fill:#6D28D9,color:#fff,stroke:#6D28D9
                    style D fill:#5B21B6,color:#fff,stroke:#5B21B6
                    style E fill:#8B5CF6,color:#fff,stroke:#8B5CF6
                    style F fill:#7E22CE,color:#fff,stroke:#7E22CE
                    style G fill:#9333EA,color:#fff,stroke:#9333EA
                </div>
            </div>
        </section>

        <!-- CountDownLatch Section -->
        <section id="countdownlatch" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="bg-purple-100 p-3 rounded-full mr-4">
                    <i class="fas fa-hourglass-half text-purple-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">CountDownLatch</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-4">核心概念</h3>
                        <p class="text-gray-700 mb-4">CountDownLatch 允许一个或多个线程等待其他线程完成操作，就像一个倒计时门闩，计数减到0时等待的线程才能继续执行。</p>
                        <div class="flex items-center mb-4">
                            <span class="bg-purple-100 text-purple-800 text-xs font-semibold px-2.5 py-0.5 rounded mr-2">一次性</span>
                            <span class="bg-purple-100 text-purple-800 text-xs font-semibold px-2.5 py-0.5 rounded">不可重置</span>
                        </div>
                        <div class="flex items-center text-sm text-gray-500">
                            <i class="fas fa-lightbulb mr-2 text-yellow-500"></i>
                            <span>适用于主线程等待多个子线程完成初始化等场景</span>
                        </div>
                    </div>
                </div>
                
                <div class="code-block">
                    <div class="code-header">
                        <span>Java 示例代码</span>
                        <i class="far fa-copy code-copy" title="复制代码"></i>
                    </div>
                    <pre class="p-4 overflow-x-auto"><code>CountDownLatch countDownLatch = new CountDownLatch(5);
for (int i = 0; i < 5; i++) {
    new Thread(() -> {
        try {
            Thread.sleep(1000* new Random().nextInt(5));
            System.out.println("同学:" + Thread.currentThread().getName() + "离开教室");
            countDownLatch.countDown();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }, i + "").start();
}
System.out.println("阿姨等待学员全部离开中。。。");
countDownLatch.await();
System.out.println("阿姨关门，下班。。");</code></pre>
                </div>
            </div>
            
            <div class="mt-8 bg-white rounded-xl shadow-md overflow-hidden">
                <div class="p-6">
                    <h3 class="text-xl font-semibold mb-4">执行流程</h3>
                    <img src="https://cdn.nlark.com/yuque/0/2023/png/21449790/1677722489617-b7dd3d07-477c-4748-9995-007bd3e047ef.png" alt="CountDownLatch流程图" class="rounded-lg w-full">
                </div>
            </div>
        </section>

        <!-- CyclicBarrier Section -->
        <section id="cyclicbarrier" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="bg-blue-100 p-3 rounded-full mr-4">
                    <i class="fas fa-flag-checkered text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">CyclicBarrier</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-4">核心概念</h3>
                        <p class="text-gray-700 mb-4">CyclicBarrier 让一组线程到达一个屏障(同步点)时被阻塞，直到最后一个线程到达屏障时，屏障才会打开，所有被屏障拦截的线程才会继续运行。</p>
                        <div class="flex items-center mb-4">
                            <span class="bg-blue-100 text-blue-800 text-xs font-semibold px-2.5 py-0.5 rounded mr-2">可循环使用</span>
                            <span class="bg-blue-100 text-blue-800 text-xs font-semibold px-2.5 py-0.5 rounded">可重置</span>
                        </div>
                        <div class="flex items-center text-sm text-gray-500">
                            <i class="fas fa-lightbulb mr-2 text-yellow-500"></i>
                            <span>适用于多线程计算数据，最后合并计算结果的场景</span>
                        </div>
                    </div>
                </div>
                
                <div class="code-block">
                    <div class="code-header">
                        <span>Java 示例代码</span>
                        <i class="far fa-copy code-copy" title="复制代码"></i>
                    </div>
                    <pre class="p-4 overflow-x-auto"><code>CyclicBarrier cyclicBarrier = new CyclicBarrier(5, () -> {
    System.out.println("5个运动员全部准备好了。。。，裁判发抢");
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
});
for (int i = 0; i < 5; i++) {
    int time = i;
    new Thread(() -> {
        String name = Thread.currentThread().getName();
        System.out.println("运动员" + name + "开始准备");
        try {
            Thread.sleep(1000 * time);
            System.out.println("运动员" + name + "准备完成");
            cyclicBarrier.await(); // 等待其他运动员准备
            System.out.println("运动员" + name + "开始跑。。。");
        } catch (InterruptedException | BrokenBarrierException e) {
            e.printStackTrace();
        }
    }, i + "").start();
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Semaphore Section -->
        <section id="semaphore" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="bg-green-100 p-3 rounded-full mr-4">
                    <i class="fas fa-traffic-light text-green-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold">Semaphore</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-4">核心概念</h3>
                        <p class="text-gray-700 mb-4">Semaphore 可以控制同时访问特定资源的线程数量，通过 acquire() 获取许可，release() 释放许可，如果没有许可可用则阻塞。</p>
                        <div class="flex items-center mb-4">
                            <span class="bg-green-100 text-green-800 text-xs font-semibold px-2.5 py-0.5 rounded mr-2">资源控制</span>
                            <span class="bg-green-100 text-green-800 text-xs font-semibold px-2.5 py-0.5 rounded">公平/非公平</span>
                        </div>
                        <div class="flex items-center text-sm text-gray-500">
                            <i class="fas fa-lightbulb mr-2 text-yellow-500"></i>
                            <span>适用于流量控制，如数据库连接池、限流等场景</span>
                        </div>
                    </div>
                </div>
                
                <div class="code-block">
                    <div class="code-header">
                        <span>Java 示例代码</span>
                        <i class="far fa-copy code-copy" title="复制代码"></i>
                    </div>
                    <pre class="p-4 overflow-x-auto"><code>public class Demo04 {
    public static void main(String[] args) throws InterruptedException {
        int N = 8;//工人数
        Semaphore semaphore = new Semaphore(5);//机器数目
        for (int i = 0; i < N; i++) {
            new MyWork(i, semaphore).start();
        }
    }

    static class MyWork extends Thread {
        private int num;
        private Semaphore semaphore;
        public MyWork(int num, Semaphore semaphore) {
            this.num = num;
            this.semaphore = semaphore;
        }
        @Override
        public void run() {
            try {
                semaphore.acquire();
                System.out.println("工人" + this.num + "占用一个机器在生产...");
                Thread.sleep(2000);
                System.out.println("工人" + this.num + "释放出机器");
                semaphore.release();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Comparison Table -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">并发工具对比表</h2>
            <div class="bg-white rounded-xl shadow-lg overflow-hidden">
                <div class="overflow-x-auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">特性</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">CountDownLatch</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">CyclicBarrier</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Semaphore</th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200">
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">用途</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">等待一个或多个线程完成</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">线程间相互等待至某个状态</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">控制资源访问的并发数</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">计数器</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">递减，不可重置</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">可重置，循环使用</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">可增加可减少</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">阻塞线程</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">调用await()的线程</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">所有调用await()的线程</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">获取不到许可的线程</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">使用场景</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">主线程等待初始化完成</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">多线程计算结果合并</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">资源池、限流</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-8">
        <div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col items-center">
                <div class="text-xl font-semibold mb-2">技术小馆</div>
                <a href="http://www.yuque.com/jtostring" class="text-gray-400 hover:text-white transition duration-300">
                    <i class="fas fa-globe mr-2"></i>www.yuque.com/jtostring
                </a>
                <div class="mt-4 flex space-x-4">
                    <a href="#" class="text-gray-400 hover:text-white">
                        <i class="fab fa-github text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white">
                        <i class="fab fa-twitter text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white">
                        <i class="fab fa-linkedin text-xl"></i>
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });

        // Copy code functionality
        document.querySelectorAll('.code-copy').forEach(button => {
            button.addEventListener('click', () => {
                const code = button.parentElement.nextElementSibling.textContent;
                navigator.clipboard.writeText(code).then(() => {
                    const originalIcon = button.className;
                    button.className = 'fas fa-check text-green-500';
                    setTimeout(() => {
                        button.className = originalIcon;
                    }, 2000);
                });
            });
        });
    </script>
</body>
</html>
```